package com.reviewcode.cachemicroservice.config;

import com.reviewcode.cachemicroservice.common.bean.ExpirationExcutor;
import com.reviewcode.cachemicroservice.common.bean.ExpirationExcutorStarter;
import com.reviewcode.cachemicroservice.common.bean.MicroCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author vcorazon
 * @type Class
 * @description TODO
 * @since 2021/07/24 22:00
 */
@Configuration
public class CacheConfiguration {

    @Value("${max_capacity}")
    Integer maxCapacity;

    @Value("${threshold}")
    Integer threshold;

    @Value("${period_cycle}")
    Integer periodCycle;

    @Bean
    public MicroCache<String, String> microCache(){
        return new MicroCache<>(maxCapacity, threshold);
    }

    @Bean
    public ExpirationExcutorStarter expirationExcutorStarter(MicroCache<String, String> microCache){
        return new ExpirationExcutorStarter(new ExpirationExcutor(microCache, periodCycle));
    }
}
